﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;
using mitasoft.ERS.Web.Core;

namespace mitasoft.ERS.Web.Utils
{
    public class CacheFactory
    {
        private static object _lockInitCache = new object();

        private static string CACHE_IssueType = "CACHE_IssueType";
        private static string CACHE_IssueStatus = "CACHE_IssueStatus";
        private static string CACHE_Projects = "CACHE_Projects";


        /// <summary>
        /// Init cache
        /// </summary>
        public static void InitCache()
        {
            lock (_lockInitCache)
            {
                using (Business.ERSEntities ctx = new Business.ERSEntities())
                {
                    CacheEngine.AddToCache(CACHE_IssueType, ctx.GetIssueTypeList());
                    CacheEngine.AddToCache(CACHE_IssueStatus, ctx.GetIssueStatuses());
                    CacheEngine.AddToCache(CACHE_Projects, ctx.GetProjects());
                }
            }
        }

        public static List<Business.IssueType> GetIssueTypeList
        {
            get
            {
                return CacheEngine.GetFromCache<List<Business.IssueType>>(CACHE_IssueType);
            }
        }
        public static List<Business.IssueStatu> GetIssueStatusList
        {
            get
            {
                return CacheEngine.GetFromCache<List<Business.IssueStatu>>(CACHE_IssueStatus);
            }
        }
        public static List<Business.Project> GetProjects
        {
            get
            {
                return CacheEngine.GetFromCache<List<Business.Project>>(CACHE_Projects);
            }
        }
    }
}